// https://leetcode.cn/problems/isomorphic-strings/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    bool isIsomorphic(string s, string t) {
        int m = s.size();
        int n = t.size();

        if (m != n) {
            return false;
        }

        unordered_map<char, char> s2t;
        unordered_map<char, char> t2s;
        for (int i = 0; i < m; i++) {
            if (s2t.count(s[i]) && s2t[s[i]] != t[i]) {
                return false;
            } 
            if (t2s.count(t[i]) && t2s[t[i]] != s[i]) {
                return false;
            }

            s2t[s[i]] = t[i];
            t2s[t[i]] = s[i];
        }
        return true;
    }
};